package com.thememaker.util;

import com.thememake.entity.ThemeFileInfo;
import com.thememake.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author yiyi.zheng
 */
public class ErrorLogUtils {
    private static ErrorLogUtils errorLogUtils;

    public static ErrorLogUtils getInstance() {
        if (errorLogUtils == null) {
            errorLogUtils = new ErrorLogUtils();
        }
        return errorLogUtils;
    }

    public void createLog(ThemeFileInfo themeFileInfo, String tips) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String err = "错误 >>> " + sdf.format(new Date(System.currentTimeMillis())) + " " + tips;
        File file = new File(themeFileInfo.getThemeDir() + File.separator + themeFileInfo.getThemeType() + File.separator + "errorlog.xml");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileUtils.saveTxt(file.toString(), err);
    }
}
